module.exports = class FileListPlugin {
  constructor(fileName = "filelist.md") {
    this.fileName = fileName;
  }
  apply(compiler) {
    compiler.hooks.emit.tap("FileListPlugin", (compilation) => {
      var fileContent = "# 文件列表\n";
      for (var fileName in compilation.assets) {
        fileContent += ` - 【${fileName}】${
          compilation.assets[fileName].size() / 1000
        }kb\n`;
      }
      compilation.assets[`${this.fileName}`] = {
        source: () => fileContent,
        size: () => fileContent.length,
      };
    });
  }
};
